package com.maisonliberte.crawller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.maisonliberte.dao.Dao;
import com.maisonliberte.entity.ImageInfo;
import com.maisonliberte.entity.PriceInfo;
import com.maisonliberte.entity.ProductInfo;
import com.maisonliberte.entity.TableInfo;
import com.maisonliberte.entity.TableOtherInfo;
import com.maisonliberte.enums.ImageSizeEnum;
import com.maisonliberte.util.CalUtil;
import com.maisonliberte.util.HtmlUtil;
import com.maisonliberte.util.JSoupUtil;
import com.maisonliberte.util.NumberUtil;
import com.maisonliberte.util.TranslateUtil;

public class StyleStoreCrawler extends AbstractCrawler{

	@Override
	public String getNextPage(String data) throws Exception {
//		
//		try{
//			String pagination = data.substring(data.indexOf("<div class=\"pagination\">"));
//			pagination = pagination.substring(0, data.indexOf("<!-- //.pagination --></div>") + 28);
//			String nextUrl = "";
//			if(pagination.indexOf("<li class=\"next\">") > -1){
//				String nextTag = pagination.substring(pagination.indexOf("<li class=\"next\">"));
//				nextTag = nextTag.substring(0, nextTag.indexOf("</li>") + 5);
//				if(nextTag.indexOf("<a href=") > -1){
//					nextUrl = nextTag.substring(nextTag.indexOf("<a href=\"") + 9);
//					nextUrl = nextUrl.substring(0, nextUrl.indexOf("\" rel="));
//				}
//			}
//			if(!nextUrl.isEmpty())
//				return String.format("http://stylestore.allabout.co.jp%s", nextUrl);
//			else
//				return "";
//			
//		}catch(Exception ex){
//			System.out.println("getNextPage" + ex.getMessage());
//			throw ex;
//		}
		
		return "";
		
	}

	@Override
	public void analyzeParsedData(String data) throws Exception {
		
		try{
			String body = data.substring(data.indexOf("<div id=\"itemList\">") + String.valueOf("<div id=\"itemList\">").length());
			body = body.substring(0, body.indexOf("<!-- //#itemList --></div>"));
			
			String startTag = "<li>";
			String endTag = "</li>";
			
			while(true){
				
				if(body.indexOf(startTag) == -1) break;
				String block = body.substring(body.indexOf(startTag));
				block = block.substring(0, block.indexOf(endTag) + String.valueOf(endTag).length());
				body = body.replace(block, "");	
				this.parsingDataList.add(block);
				
			}
			
			String startLastTag = "<li class=\"last\">";
			String endLastTag = "</li>";
			
			while(true){
				
				if(body.indexOf(startLastTag) == -1) break;
				String block = body.substring(body.indexOf(startLastTag));
				block = block.substring(0, block.indexOf(endLastTag) + String.valueOf(endLastTag).length());
				body = body.replace(block, "");	
				this.parsingDataList.add(block);
				
			}
			
			
			
		}catch(Exception ex){
			System.out.println("analyzeParsedData " + ex.getMessage());
			System.out.println("parsingDataList : " + parsingDataList.size());
			throw ex;
		}
		
	}

	@Override
	public void analyzerProductDetailInfo(String data, ProductInfo pInfo)
			throws Exception {

		String url = "";
		String weight = "";
		String spec = "";
		String qty = "";
		int price = 0;
		
		try{
			
			Document doc = Jsoup.parse(data);
			
			TableInfo prodTable = new TableInfo();
			TableOtherInfo prodTableOther = new TableOtherInfo();
			pInfo.setTableInfo(prodTable);
			pInfo.setTableOther(prodTableOther);
			prodTable.setCate(this.category.value());
			prodTable.setForwardFee(true);
			//prodTable.setNumber(Dao.getInstance().getNewProductNumber());
			
			//URL
			String tmp = data.substring(data.indexOf("<meta property=\"og:url\""));
			String tmp_sub = tmp.substring(0, tmp.indexOf("/>") + String.valueOf("/>").length());
			tmp_sub = tmp_sub.substring(tmp_sub.indexOf("content=") + String.valueOf("content=").length());
			tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("/>"));
			url = tmp_sub.replace("\"", "").trim();
			prodTable.setSourceUrl(url);
			
			// 商品名
			//<meta property="og:title" content="m+/レザーバッグ TENERA ブラック" />
			if(url.equals("http://stylestore.allabout.co.jp/mojo/ProductInfo/sku/EC046-10-5000-0079/")){
				System.out.println("hit!!");
			}
			
			tmp = data.substring(data.indexOf("<meta property=\"og:title\""));
			tmp_sub = tmp.substring(0, tmp.indexOf("/>") + String.valueOf("/>").length());
			tmp_sub = tmp_sub.substring(tmp_sub.indexOf("content=") + String.valueOf("content=").length());
			tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("/>"));
			tmp_sub = tmp_sub.replace("\"", "");
			String prodName = tmp_sub;
			prodTable.setName_jp(prodName.trim());
			prodTable.setName(TranslateUtil.translateJpnToKor(prodName));
			
			// from Staff
			String fromStaff = "";
			Element em = JSoupUtil.getTagElementByDivClass(doc, "fromStaff", "p");
			if(em != null){
				fromStaff = em.text();
			}

			prodTableOther.setStaff_comment_jpn(fromStaff.replace("\t", "").trim());
			prodTableOther.setStaff_comment(TranslateUtil.translateJpnToKor(prodTableOther.getStaff_comment_jpn()));
			
			// SPEC
			spec = "";
			// Weight
			weight = "0";
			try{
				if(tmp.indexOf("<div class=\"spec\">") > -1){
					tmp_sub = tmp.substring(tmp.indexOf("<div class=\"spec\">"));
					tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("<span class=\"r\">") + String.valueOf("<span class=\"r\">").length());
					spec = tmp_sub.replace("<div class=\"spec\">", "").replace("<span class=\"r\">", "").replace("\t", "").trim();
					if(tmp.indexOf("■重量") > -1){
						tmp_sub = tmp.substring(tmp.indexOf("■重量") + String.valueOf("■重量").length());
						if(tmp_sub.indexOf("<br>") > -1){
							tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("<br>"));
						}else if(tmp_sub.indexOf("<br />") > -1){
							tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("<br />"));	
						}

						
						tmp_sub = tmp_sub.replace("キログラム", "kg").replace("グラム", "g");
						tmp_sub = NumberUtil.changeZenToHan(tmp_sub);
						
						int findIdx = -1;
						findIdx = tmp_sub.indexOf("kg");
						if(findIdx > -1){
							tmp_sub = tmp_sub.substring(0, findIdx + String.valueOf("kg").length());
						}
						
						if(findIdx == -1 && (findIdx = tmp_sub.indexOf("g")) > -1){
							tmp_sub = tmp_sub.substring(0, findIdx + String.valueOf("g").length());
						}
						
						if(findIdx == -1 && (findIdx = tmp_sub.indexOf("ｋｇ")) > -1){
							tmp_sub = tmp_sub.substring(0, findIdx + String.valueOf("ｋｇ").length());
						}	
						
						if(findIdx == -1 && (findIdx = tmp_sub.indexOf("ｇ")) > -1){
							tmp_sub = tmp_sub.substring(0, findIdx + String.valueOf("ｇ").length());
						}
						
						tmp_sub = tmp_sub.replace("\t", "").replace(":", "").replace("約", "").replace("：", "").replace("　", "").replace(" ", "").trim();
						boolean isKg = false;
						if(tmp_sub.indexOf("kg") > -1 || tmp_sub.indexOf("ｋ") > -1 || tmp_sub.indexOf("k") > -1){
							isKg = true;
							tmp_sub = tmp_sub.replace("kg", "").replace("ｋｇ", "").replace("ｋ", "").replace("ｇ", "");
						}else if(tmp_sub.indexOf("g") > -1 || tmp_sub.indexOf("ｇ") > -1){
							tmp_sub = tmp_sub.replace("g", "").replace("ｇ", "");
						}else{
							tmp_sub = tmp_sub.replace("k", "").replace("g", "").replace("ｋ", "").replace("ｇ", "");
						}
						if(!tmp_sub.trim().isEmpty() && isKg){
							tmp_sub = NumberUtil.filter(tmp_sub, false);
							int _weight = 0;
							if(tmp_sub.indexOf(".") > -1){
								float w = Float.valueOf(tmp_sub) * 1000;
								_weight = Math.round(w);
								weight = String.valueOf(_weight);
							}else{
								weight = String.valueOf(Integer.valueOf(tmp_sub)/1000);	
							}
						}else if(!tmp_sub.trim().isEmpty()){
							tmp_sub = NumberUtil.filter(tmp_sub, true);
							if(tmp_sub.indexOf(".") > -1){
								BigDecimal bd = new BigDecimal(tmp_sub);
								weight = String.valueOf(bd.intValue());
							}else{
								weight = String.valueOf(Integer.valueOf(tmp_sub));	
							}
						}
					}
					
				}
			}catch(NumberFormatException ne){
				//
				weight = "0";
			}
			
			prodTable.setExplan_jpn(spec.replace("\t", "").trim());
			prodTable.setExplan(TranslateUtil.translateJpnToKor(prodTable.getExplan_jpn()));
			prodTable.setWeight(Integer.valueOf(weight));
			
			// SELECTOR
			boolean isLong = false;
			boolean isFunction = false;
			boolean isDesign = false;
			boolean isEcho = false;
			boolean isTradition = false;
			boolean isRare = false;
			String selectorId = "";
			
//			if(data.indexOf("<div class=\"selectorArea\">") > -1){
//			
//				tmp = data.substring(data.indexOf("<div class=\"selectorArea\">"));
//				tmp = tmp.substring(0, tmp.indexOf("<!-- //.selectorArea --></div>") + String.valueOf("<!-- //.selectorArea --></div>").length());
//				tmp_sub = tmp.substring(tmp.indexOf("<script type=\"text/javascript\""));
//				tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf(">") + String.valueOf(">").length());
//				String selectorUrl = HtmlUtil.getSrcOfScriptTag(tmp_sub, "charset=");
//				if(selectorUrl != null && selectorUrl.indexOf("http:") == -1){
//					selectorUrl = "http:" + selectorUrl;
//					String selectResult = HttpUtil.httpGet(selectorUrl, "Shift_JIS");
//					if(selectResult.indexOf("<a") > -1){
//						tmp_sub = selectResult.substring(selectResult.indexOf("<a"));
//						tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf(">") + String.valueOf(">").length());
//						tmp_sub = HtmlUtil.getHrefOfATag(tmp_sub, "target=");
//						//http://tblog.stylestore.allabout.co.jp/blog/S00049/
//						//http://stylestore.allabout.co.jp/taito/
//						if(tmp_sub.indexOf("tblog.stylestore.allabout.co.jp") > -1){
//							selectorId = tmp_sub.replace("http://", "").replace("tblog.stylestore.allabout.co.jp", "").replace("stylestore.allabout.co.jp", "").replace("blog", "").replace("/", "").trim();
//						}else if(tmp_sub.indexOf("stylestore.allabout.co.jp") > -1){
//							selectorId = tmp_sub.replace("http://", "").replace("tblog.stylestore.allabout.co.jp", "").replace("stylestore.allabout.co.jp", "").replace("blog", "").replace("/", "").trim();
//						}else if(tmp_sub.indexOf("stylestore.jp") > -1){
//							//http://stylestore.jp/blog/blog/T00318/
//							selectorId = tmp_sub.replace("http://", "").replace("stylestore.jp", "").replace("blog", "").replace("/", "").trim();
//						}		
//					}
//					else{
//						selectorId = "S99999";
//					}
//				}
//				
//				tmp = data;
//				String md_icon_flg = tmp.substring(tmp.indexOf("var md_icon_flg="));
//				md_icon_flg = md_icon_flg.substring(0, md_icon_flg.indexOf(";") + String.valueOf(";").length());
//				md_icon_flg = md_icon_flg.replace("var md_icon_flg=", "").replace("\t", "").replace(";", "").replace("\"", "").trim();
//				
//				isLong = md_icon_flg.substring(0, 1).equals("1");
//				isFunction = md_icon_flg.substring(1, 2).equals("1");
//				isDesign = md_icon_flg.substring(2, 3).equals("1");
//				isEcho = md_icon_flg.substring(3, 4).equals("1");
//				isTradition = md_icon_flg.substring(4, 5).equals("1");
//				isRare = md_icon_flg.substring(5, 6).equals("1");
//				
//			}else{
				selectorId = "S99999";
//			}
			
			prodTableOther.setS_long(isLong ? 1 : 0);
			prodTableOther.setS_function(isFunction ? 1 : 0);
			prodTableOther.setS_design(isDesign ? 1 : 0);
			prodTableOther.setS_echo(isEcho ? 1 : 0);
			prodTableOther.setS_tradition(isTradition ? 1 : 0);
			prodTableOther.setS_rare(isRare ? 1 : 0);
			prodTableOther.setStaff_id(selectorId);
			
			String creatorId = "";
//			if(data.indexOf("<div class=\"creatorArea\">") > -1){
//				tmp = data.substring(data.indexOf("<div class=\"creatorArea\">"));
//				tmp = tmp.substring(0, tmp.indexOf("<!-- //.creatorArea --></div>") + String.valueOf("<!-- //.creatorArea --></div>").length());
//				tmp_sub = tmp.substring(tmp.indexOf("<div class=\"faceArea clear\">"));
//				tmp_sub = tmp_sub.substring(tmp_sub.indexOf("<a"));
//				tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf(">") + String.valueOf(">").length());
//				creatorId = HtmlUtil.getHrefOfATag(tmp_sub, "target=");
//				if(creatorId != null){
//					if(creatorId.indexOf("http:") == -1){
//						creatorId = "http:" + creatorId;
//					}
//					if(creatorId.indexOf("tblog.stylestore.allabout.co.jp") > -1){
//						creatorId = creatorId.replace("http://", "").replace("tblog.stylestore.allabout.co.jp", "").replace("stylestore.allabout.co.jp", "").replace("blog", "").replace("/", "").trim();
//					}else if(tmp_sub.indexOf("stylestore.allabout.co.jp") > -1){
//						creatorId = creatorId.replace("http://", "").replace("tblog.stylestore.allabout.co.jp", "").replace("stylestore.allabout.co.jp", "").replace("blog", "").replace("/", "").trim();
//					}else if(creatorId.indexOf("stylestore.jp") > -1){
//						//http://stylestore.jp/blog/blog/T00318/
//						creatorId = creatorId.replace("http://", "").replace("stylestore.jp", "").replace("blog", "").replace("/", "").trim();
//					}
//				}
//			}
//			prodTableOther.setMaker_id(creatorId);
//			
//			String brandId = "";
//			if(data.indexOf("<div id=\"brandArea\">") > -1){
//				tmp = data.substring(data.indexOf("<div id=\"brandArea\">"));
//				tmp_sub = tmp.substring(tmp.indexOf("<a "));
//				tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf(">") + String.valueOf(">").length());
//				brandId = HtmlUtil.getHrefOfATag(tmp_sub, "target=");
//				if(brandId != null){
//					if(brandId.indexOf("http:") == -1){
//						brandId = "http:" + brandId;
//					}
//					//brandId = brandId.replace("http://tblog.stylestore.allabout.co.jp/blog/", "").replace("http://stylestore.allabout.co.jp/search/brand", "").replace("/", "").trim();
//					if(brandId.indexOf("tblog.stylestore.allabout.co.jp") > -1){
//						brandId = brandId.replace("http://", "").replace("tblog.stylestore.allabout.co.jp", "").replace("stylestore.allabout.co.jp", "").replace("blog", "").replace("/", "").trim();
//					}else if(brandId.indexOf("stylestore.allabout.co.jp") > -1){
//						brandId = brandId.replace("http://", "").replace("tblog.stylestore.allabout.co.jp", "").replace("stylestore.allabout.co.jp", "").replace("blog", "").replace("/", "").trim();
//					}else if(brandId.indexOf("stylestore.jp") > -1){
//						//http://stylestore.jp/blog/blog/T00318/
//						brandId = brandId.replace("http://", "").replace("stylestore.jp", "").replace("blog", "").replace("/", "").trim();
//					}
//					brandId = brandId.replace("search", "").replace("brand", "");
//				}
//			}
//			prodTableOther.setBrand_id(brandId);
			
			// 価格
			tmp = data.substring(data.indexOf("<div class=\"btnArea\""));
			tmp_sub = tmp.substring(tmp.indexOf("<span itemprop=\"price\">"));
			tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("</span>") + String.valueOf("</span>").length());
			String orgPrice = HtmlUtil.getTextLabelOfSpanTag(tmp_sub).replace(",", "").trim();
			price = 0;
			int conPrice = 0;
			int carrage = 0;
			
			// 送料
			String localCarriage = "0"; 
			if(tmp.indexOf("<span class=\"r b\">送料無料</span><br />") == -1){
				tmp_sub = tmp.substring(tmp.indexOf("■送料"));
				tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("<br />"));
				localCarriage = HtmlUtil.getAmount(tmp_sub, "&yen;", true);
				localCarriage = localCarriage.replace(",", "");
				
			}
			if(localCarriage.isEmpty())localCarriage = "0";
			
			PriceInfo priceInfo = CalUtil.getPrice(Integer.valueOf(orgPrice), Integer.valueOf(localCarriage), Integer.valueOf(weight));
			pInfo.setPriceInfo(priceInfo);
			prodTable.setPrice(priceInfo.Price());
			prodTable.setConsumerPrice(priceInfo.ConPrice());
			prodTable.setCarriage(String.valueOf(priceInfo.getEmsFee()));
			
			// 在庫
			qty = "0";
			if(tmp.indexOf("■在庫　：") > -1){
				tmp_sub = tmp.substring(tmp.indexOf("■在庫　："));
				if(tmp_sub.indexOf("<span itemprop=\"availability\" content=\"in_stock\">") > -1){
					tmp_sub = tmp_sub.substring(tmp_sub.indexOf("<span itemprop=\"availability\" content=\"in_stock\">"));
					tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("</span>") + String.valueOf("</span>").length());
					qty = tmp_sub.replace("<span itemprop=\"availability\" content=\"in_stock\">", "").replace("</span>", "");
				}	
				if(!NumberUtil.isNumber(qty)){
					qty = "6";
				}
					
			}else{
				qty = "6";
			}

			prodTable.setQty(Integer.valueOf(qty));
			
		}catch(Exception ex){
			System.out.println("[analyzerProductDetailInfo][url] " + url);
			System.out.println("[analyzerProductDetailInfo][weight] " + weight);
			System.out.println("[analyzerProductDetailInfo][spec] " + spec);
			System.out.println("[analyzerProductDetailInfo][qty] " + qty);
			System.out.println("[analyzerProductDetailInfo][price] " + price);
			System.out.println("[analyzerProductDetailInfo]" + ex.getMessage());
			throw ex;
		}
		
	}

	@Override
	public void analyzerImageInfo(String data, ProductInfo pInfo)
			throws Exception {
		
		try{
			
			Map<ImageSizeEnum, List<ImageInfo>> imageList = new HashMap<ImageSizeEnum, List<ImageInfo>>();
			String tmp = data;
			String tmp_sub = "";
			String mainImg = "";
			String middleImg = "";
			String listImg = "";
			String displayImg = "";
			String smallImg = "";
			List<String> otherImg = new ArrayList<String>();
			List<String> detailImg = new ArrayList<String>();
			
			Document doc = Jsoup.parse(data);
			
			//상품 이미지 Large
			if(doc.html().indexOf("<!-- 画像ビューワー非対応 -->") > -1){

				Element mainImgEm = JSoupUtil.getTagElementByDivClass(doc, "MainImg", "img");
				if(mainImgEm != null){
					mainImg = mainImgEm.attr("src");
					if(mainImg.indexOf("http:") == -1) mainImg = "http:" + mainImg;
				}
				
				Elements subImgEms = JSoupUtil.getTagElementsByDivClass(doc, "SubImg", "a");
				if(subImgEms != null){
					for(Element em : subImgEms){
						String src = em.attr("href");
						if(src.indexOf("http:") == -1) src = "http:" + src;
						otherImg.add(src.trim());
					}	
				}
				
				Elements usedImgEms = JSoupUtil.getTagElementsByDivClass(doc, "UseImg", "img");
				if(usedImgEms != null){
					for(Element em : usedImgEms){
						String src = em.attr("src");
						if(src.indexOf("http:") == -1) src = "http:" + src;
						detailImg.add(src.trim());
					}	
				}
				
			}else{
				
				Elements ems = doc.getElementsByClass("MainImg");
				tmp = ems.get(0).html();
				tmp_sub = tmp.substring(tmp.indexOf("<script type=\"text/javascript\">"));
				tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf("</script>") + String.valueOf("</script>").length());
				tmp_sub = tmp_sub.substring(tmp_sub.indexOf("var sku"));
				tmp_sub = tmp_sub.substring(0, tmp_sub.indexOf(";"));
				String sku = tmp_sub.replace("var sku", "").replace("\t", "").replace("'", "").replace("=", "").trim();
				String url_template = "http://ccm.stylestore.allabout.co.jp/product_img_conv.php?f=%s&w=%d&h=%d";
				mainImg = String.format(url_template, sku, 360, 360);
				middleImg = String.format(url_template, sku, 250, 250);
				listImg = String.format(url_template, sku, 150, 150);
				displayImg = String.format(url_template, sku, 120, 120);
				smallImg = String.format(url_template, sku, 80, 80);
				
				for(int i = 1; i < 19; i++){
					//if(otherImg.size() > 15) break;
					String sku_other = String.format("%s_%02d", sku, i);
					try{
						String __url = String.format(url_template, sku_other, 360, 360);
						Jsoup.connect(__url).timeout(10000);
						Document _doc = Jsoup.connect(__url).get();
					}catch(org.jsoup.UnsupportedMimeTypeException e){
						otherImg.add(String.format(url_template, sku_other, 360, 360));
					}catch(org.jsoup.HttpStatusException e){
						//
					}catch(Exception e){
						//
					}
				}
				
				Elements usedImgEms = JSoupUtil.getTagElementsByDivClass(doc, "UseImg", "img");
				if(usedImgEms != null){
					for(Element em : usedImgEms){
						String src = em.attr("src");
						if(src.indexOf("http:") == -1) src = "http:" + src;
						detailImg.add(src.trim());
					}	
				}
			}
			String productCode = getProductCode(data);
			// LARGE
			imageList.put(ImageSizeEnum.LARGE_500px, new ArrayList<ImageInfo>());
			ImageInfo imgInfo = new ImageInfo(mainImg);
			imgInfo.setCode(productCode);
			imageList.get(ImageSizeEnum.LARGE_500px).add(imgInfo);
			
			//middle
			imageList.put(ImageSizeEnum.MIDDLE_250px, new ArrayList<ImageInfo>());
			if(!middleImg.isEmpty()){
				ImageInfo middelImgInfo = new ImageInfo(middleImg);
				imgInfo.setCode(productCode);
				imageList.get(ImageSizeEnum.MIDDLE_250px).add(middelImgInfo);
			}
			
			//list
			imageList.put(ImageSizeEnum.LIST_150px, new ArrayList<ImageInfo>());
			if(!listImg.isEmpty()){
				ImageInfo listImgInfo = new ImageInfo(listImg);
				imgInfo.setCode(productCode);
				imageList.get(ImageSizeEnum.LIST_150px).add(listImgInfo);
			}
			
			//display
			imageList.put(ImageSizeEnum.DISPLAY_120px, new ArrayList<ImageInfo>());
			if(!displayImg.isEmpty()){
				ImageInfo disImgInfo = new ImageInfo(displayImg);
				imgInfo.setCode(productCode);
				imageList.get(ImageSizeEnum.DISPLAY_120px).add(disImgInfo);
			}
			
			//small
			imageList.put(ImageSizeEnum.SMALL_80px, new ArrayList<ImageInfo>());
			if(!displayImg.isEmpty()){
				ImageInfo smallImgInfo = new ImageInfo(smallImg);
				imgInfo.setCode(productCode);
				imageList.get(ImageSizeEnum.SMALL_80px).add(smallImgInfo);
			}
			
			// OTHER OTHER
			imageList.put(ImageSizeEnum.OTHER_IMG, new ArrayList<ImageInfo>());
			for(String src : otherImg){
				ImageInfo otherImgInfo = new ImageInfo(src);
				imgInfo.setCode(productCode);
				imageList.get(ImageSizeEnum.OTHER_IMG).add(otherImgInfo);
			}
			
			// DETAIL
			imageList.put(ImageSizeEnum.DETAIL_IMG, new ArrayList<ImageInfo>());
			for(String src : detailImg){
				ImageInfo detailImgInfo = new ImageInfo(src);
				imgInfo.setCode(productCode);
				imageList.get(ImageSizeEnum.DETAIL_IMG).add(detailImgInfo);
			}
			
			pInfo.setImageList(imageList);
//			System.out.println("main image parsing : " + mainImg);
//			System.out.println("middle image parsing : " + middleImg);
//			System.out.println("list image parsing : " + listImg);
//			System.out.println("display image parsing : " + displayImg);
//			System.out.println("small image parsing : " + smallImg);
			
		}catch(Exception ex){
			System.out.println("ㅇㅇㅇㅇㅇㅇㅇㅇ analyzerImageInfo" + ex.getMessage());
			//System.out.println(data);
			throw ex;
		}
		
		
		
	}

	@Override
	public String getDetailUrl(String data) throws Exception {

		try{
			//<a class="fadeimg" href="/mojo/ProductInfo/sku/KA143-42-0000-0064/">
			//getHrefOfATag
			String tmp = data.substring(data.indexOf("<a class=\"fadeimg\""));
			tmp = tmp.substring(0, tmp.indexOf(">")+1);
			String url = HtmlUtil.getHrefOfATag(tmp, "\">");
			if(url.indexOf("http://stylestore.allabout.co.jp/") == -1){
				url = String.format("http://stylestore.jp%s", url);
			}
			
			if(Dao.getInstance().isDuplicateProduct(url)){
				System.out.println(String.format("%s is duplicate url", url));
				return null;
			}
			
			return url;
			
		}catch(Exception ex){
			System.out.print(data);
			System.out.println("getDetailUrl" + ex.getMessage());
			throw ex;
		}
	}

	@Override
	public String requestDetailUrl(String url) throws Exception {
		//return HttpUtil.httpGet(url, "Shift_JIS");
		Document doc = Jsoup.connect(url).get();
		return doc.html();
	}
	@Override
	protected String getProductCode(String data){
		//<meta property="og:url" content="http://stylestore.allabout.co.jp/mojo/ProductInfo/sku/HA116-10-5000-A007/" />
		String tmp = data.substring(data.indexOf("<meta property=\"og:url\""));
		tmp = tmp.substring(0, tmp.indexOf(">") + 1);
		tmp = tmp.substring(tmp.indexOf("content=") + String.valueOf("content=").length());
		tmp = tmp.substring(0, tmp.indexOf("/>"));
		tmp = tmp.replace("\"", "").replace("http://stylestore.jp/item/", "").replace("/", "");
		return tmp.trim();
	}

	@Override
	protected String getListImg(String data) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
